package behavioral.memento;

/**
 * @ClassName: Originator
 * @Description: 发起人类：拥有创建备忘录、从备忘录中恢复状态的方法
 * @Author: liu-hao
 * @Date: 2023-04-11 23:13
 * @Version: 1.0
 **/
public class Originator {
    private String name;
    private int age;

    public Originator(String name, int age) {
        this.name = name;
        this.age = age;
    }

    // 创建备忘录对象
    public Memento createMemento() {
        return new Memento(name, age);
    }

    // 根据备忘录对象恢复记录的状态
    public void setMemento(Memento memento) {
        this.name = memento.getName();
        this.age = memento.getAge();
    }

    public void display() {
        System.out.println("发起人：name=" + name + ", age=" + age);
    }
}
